package cac.fenjian.resource.mspartbasic.api;

import cac.fenjian.resource.MsPart.dto.MsPartBasicDTO;
import com.cac.dme.adapter.rest.client.RestClient;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;


@Component
@RestController
@RequestMapping("/partApi")
public class MsPartBasicApi {
    /**
     *服务编码
     */
    private static final String SERVICE_CODE="xdCommonData";
    private static final String BASE_PATH = "/msPartBasic/";

    @Autowired
    private RestClient restClient;


    /**
     * 按条件分页查询
     * @param queryReqBean 查询条件
     * @return QueryRespBean<MsPartBasicDTO>
     */

    @PostMapping("/searchByPage")
    public QueryRespBean<MsPartBasicDTO> searchByPage(@RequestBody QueryReqBean<MsPartBasicDTO> queryReqBean) {
        String url = BASE_PATH + "/searchByPage/s1";
        ResponseMsg<QueryRespBean<MsPartBasicDTO>> responseMsg = restClient.doPost(SERVICE_CODE, url, queryReqBean, new ParameterizedTypeReference<ResponseMsg<QueryRespBean<MsPartBasicDTO>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 通过主键查询单条记录
     *
     * @param ms_part_id 主键id
     * @return MsPartBasicDTO
     */
    @GetMapping("/getById/{ms_part_id}")
    public MsPartBasicDTO get(@PathVariable String ms_part_id) {
        String url = BASE_PATH + "/search/s1/" + ms_part_id;
        ResponseMsg<MsPartBasicDTO> responseMsg = restClient.doGet(SERVICE_CODE, url, new ParameterizedTypeReference<ResponseMsg<MsPartBasicDTO>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 新增对象
     *
     * @param msPartBasicDTO 保存对象
     * @return String
     */
    @PostMapping("/insert")
    public String save(@RequestBody MsPartBasicDTO msPartBasicDTO) {
        String url = BASE_PATH + "/save/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, msPartBasicDTO, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 修改部分对象字段
     *
     * @param msPartBasicDTO 修改对象
     * @return Integer
     */
    @PostMapping("/update")
    public Integer updateSensitive(@RequestBody MsPartBasicDTO msPartBasicDTO) {
        String url = BASE_PATH + "/update/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msPartBasicDTO, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 修改全部对象字段
     *
     * @param msPartBasicDTO 修改对象
     * @return Integer
     */
    @PostMapping("/updateAll")
    public Integer updateAll(@RequestBody MsPartBasicDTO msPartBasicDTO) {
        String url = BASE_PATH + "/updateAll/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msPartBasicDTO, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 按主键单条删除
     *
     * @param id 主键id
     * @return Integer
     */
    @PostMapping("/deleteById")
    public Integer deleteById(@RequestBody String id) {
        String url = BASE_PATH + "/delete/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 批量删除
     *
     * @param ids 逗号分隔的id串
     * @return Integer
     */
    @PostMapping("/deleteByIds")
    public Integer deleteByIds(@RequestBody String[] ids) {
        String url = BASE_PATH + "/deleteByIds/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, ids, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

}
